import os


def custom_rmtree(path):

    if not os.path.exists(path):
        print(f"路径 {path} 不存在")
        return
    if not os.path.isdir(path):
        print(f"{path} 不是一个目录")
        return

    for root, dirs, files in os.walk(path, topdown=False):
        for name in files:
            os.remove(os.path.join(root, name))
        for name in dirs:
            os.rmdir(os.path.join(root, name))


    try:
        os.rmdir(path)
        print(f"目录 {path} 及其内容已成功删除")
    except OSError as e:
        print(f"在删除 {path} 时发生错误: {e.strerror}")


import os


def custom_rmtree(path):

    if not os.path.exists(path):
        print(f"路径 {path} 不存在")
        return
    if not os.path.isdir(path):
        print(f"{path} 不是一个目录")
        return


    for root, dirs, files in os.walk(path, topdown=False):
        for name in files:
            os.remove(os.path.join(root, name))
        for name in dirs:
            os.rmdir(os.path.join(root, name))


    try:
        os.rmdir(path)
        print(f"目录 {path} 及其内容已成功删除")
    except OSError as e:
        print(f"在删除 {path} 时发生错误: {e.strerror}")



